<template>
  <div class="full-box shadow-box padding-box">
    <OperateCommon :showBack="true" @back="goBack">
      <!-- <template #operate>
        <el-button size="default" @click="operate(10)">了解</el-button>
        <el-button type="primary" size="default" @click="operate(20)"
          >关注</el-button
        >
        <el-button type="warning" size="default" @click="operate(30)"
          >督办</el-button
        >
        <el-button type="danger" size="default" @click="operate(40)"
          >查处</el-button
        >
      </template> -->
    </OperateCommon>

    <el-collapse v-model="activeNames" :accordion="false">
      <el-collapse-item v-if="detail" title="预警详情" name="1">
        <div class="desc">
          <label>预警单位：</label>
          <span>
            {{ detail.dept_name }}
          </span>
        </div>
        <div class="desc">
          <label>预警发生时间：</label>
          <span>
            {{ detail.trigger_time }}
          </span>
        </div>
        <div class="desc">
          <label>预警节点：</label>
          <span>
            {{ detail.scene }}
          </span>
        </div>
        <div class="desc">
          <label>预警内容：</label>
          <span>
            {{ detail.warning_content }}
          </span>
        </div>

        <template v-if="detail.assign_id != ''">
          <div class="desc">
            <label>承办单位：</label>
            <span>
              {{ detail.undertake_dept_name }}
            </span>
          </div>
          <div class="desc">
            <label>交办意见：</label>
            <span>
              {{ detail.assign_opinion }}
            </span>
          </div>
          <div class="desc">
            <label>附件材料：</label>
            <CommonUpload
              tableName="red-alert-assign"
              :useType="1"
              :pid="detail.assign_id"
              :showUploadBtn="false"
              :disabled="true"
            ></CommonUpload>
          </div>
          <div class="desc">
            <label>交办单位：</label>
            <span>
              {{ detail.assign_dept_name }}
            </span>
          </div>
          <div class="desc">
            <label>交办时间：</label>
            <span>
              {{ detail.assign_time }}
            </span>
          </div>
        </template>
      </el-collapse-item>
      <el-collapse-item v-if="detail" title="问题移送详情" name="2">
        <div class="desc">
          <label>移交单位：</label>
          <span>
            {{ detail.warningTransfer.dept_name }}
          </span>
        </div>
        <div class="desc">
          <label>移交时间：</label>
          <span>
            {{ detail.warningTransfer.transfer_time }}
          </span>
        </div>
        <div class="desc">
          <label>问题描述：</label>
          <span>
            {{ detail.warningTransfer.problem }}
          </span>
        </div>
        <div class="desc">
          <label>附件：</label>
          <CommonUpload
            tableName="question-transfer"
            useType="transfer"
            :pid="detail.warningTransfer.id"
            :showUploadBtn="false"
            :disabled="true"
          ></CommonUpload>
        </div>
        <div class="desc">
          <label>状态：</label>
          <span>
            {{ detail.warningTransfer.status_text }}
          </span>
        </div>
      </el-collapse-item>
      <el-collapse-item v-if="detail" title="问题接收" name="3">
        <template v-if="!detail.warningTransfer.receive_time">
          <el-form
            :model="acceptForm"
            ref="acceptForm"
            :rules="acceptRules"
            label-width="150px"
            :inline="false"
          >
            <el-form-item label="接收意见" prop="receive_opinion">
              <el-input
                type="textarea"
                v-model="acceptForm.receive_opinion"
                :autosize="{
                  minRows: 3,
                  maxRows: 6,
                }"
              ></el-input>
            </el-form-item>
            <el-form-item label="" prop="">
              <el-button type="primary" @click="acceptProblem">接收</el-button>
            </el-form-item>
          </el-form>
        </template>
        <template v-if="detail.warningTransfer.receive_time">
          <div class="desc">
            <label>接收意见：</label>
            <span>
              {{ detail.warningTransfer.receive_opinion }}
            </span>
          </div>
          <div class="desc">
            <label>接收时间：</label>
            <span>
              {{ detail.warningTransfer.receive_time }}
            </span>
          </div>
        </template>
      </el-collapse-item>
      <el-collapse-item
        v-if="detail && detail.warningTransfer.receive_time"
        title="问题交办"
        name="4"
      >
        <template
          v-if="
            detail.warningTransfer &&
            (detail.warningTransfer.status == 0 ||
              detail.warningProblemAssign.status == 2)
          "
        >
          <el-form
            :model="assignForm"
            ref="assignForm"
            :rules="assignRules"
            label-width="150px"
          >
            <el-form-item label="交办单位" prop="assign_dept_id">
              <DeptCascader
                :options="dept"
                :defaultChecked.sync="assignForm.assign_dept_id"
                :clearable="false"
                @change="changeAssignDept"
              ></DeptCascader>
            </el-form-item>
            <el-form-item label="交办时间" prop="">
              <el-date-picker
                v-model="assignForm.assign_date"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                disabled
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="问题描述" prop="problem_desc">
              <el-input
                type="textarea"
                v-model="assignForm.problem_desc"
                :autosize="{ minRows: 3, maxRows: 6 }"
              ></el-input>
            </el-form-item>
            <el-form-item label="附件" prop="">
              <CommonUpload
                tableName="question-transfer"
                useType="assign"
              ></CommonUpload>
            </el-form-item>
            <el-form-item label="承办单位" prop="undertake_dept_id">
              <DeptCascader
                :options="dept"
                :defaultChecked.sync="assignForm.undertake_dept_id"
                @change="changeDept"
              ></DeptCascader>
            </el-form-item>
            <el-form-item label="交办意见" prop="assign_opinion">
              <el-input
                type="textarea"
                v-model="assignForm.assign_opinion"
                :autosize="{ minRows: 3, maxRows: 6 }"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-button type="primary" @click="assignProblem">交办</el-button>
            </el-form-item>
          </el-form>
        </template>
        <template
          v-if="
            detail.warningTransfer &&
            detail.warningTransfer.status != 0 &&
            detail.warningProblemAssign.status != 2
          "
        >
          <div class="desc">
            <label>交办单位：</label>
            <span>
              {{ detail.warningProblemAssign.assign_dept_name }}
            </span>
          </div>
          <div class="desc">
            <label>交办时间：</label>
            <span>
              {{ detail.warningProblemAssign.assign_date }}
            </span>
          </div>
          <div class="desc">
            <label>问题描述：</label>
            <span>
              {{ detail.warningProblemAssign.problem_desc }}
            </span>
          </div>
          <div class="desc">
            <label>附件：</label>
            <CommonUpload
              tableName="question-transfer"
              useType="assign"
              :pid="detail.warningProblemAssign.id"
              :showUploadBtn="false"
              :disabled="true"
            ></CommonUpload>
          </div>
          <div class="desc">
            <label>承办单位：</label>
            <span>
              {{ detail.warningProblemAssign.undertake_dept_name }}
            </span>
          </div>
          <div class="desc">
            <label>交办意见：</label>
            <span>
              {{ detail.warningProblemAssign.assign_opinion }}
            </span>
          </div>
        </template>
      </el-collapse-item>
      <el-collapse-item
        v-if="detail && detail.warningProblemAssign"
        title="问题反馈"
        name="5"
      >
        <template
          v-if="detail.warningProblemAssign.status == 0 && user.homeRole != 3"
        >
          <el-form
            :model="feedbackForm"
            ref="feedbackForm"
            :rules="feedbackRules"
            label-width="80px"
            :inline="false"
            size="normal"
          >
            <el-form-item label="接收意见" prop="feedback">
              <el-input
                type="textarea"
                v-model="feedbackForm.feedback"
                :autosize="{
                  minRows: 3,
                  maxRows: 6,
                }"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-button type="primary" @click="feedbackProblem(1)"
                >接收</el-button
              >
              <el-button type="danger" @click="feedbackProblem(2)"
                >退回</el-button
              >
            </el-form-item>
          </el-form>
        </template>

        <template
          v-if="detail.warningProblemAssign.status == 0 && user.homeRole == 3"
        >
          <div style="text-align: center">
            <b>未反馈</b>
          </div>
        </template>

        <template v-if="detail.warningProblemAssign.status != 0">
          <div class="desc">
            <label>反馈状态：</label>
            <span>
              {{ detail.warningProblemAssign.status_text }}
            </span>
          </div>
          <div class="desc">
            <label>反馈意见：</label>
            <span>
              {{ detail.warningProblemAssign.feedback }}
            </span>
          </div>
          <div class="desc">
            <label>反馈时间：</label>
            <span>
              {{ detail.warningProblemAssign.feedback_date }}
            </span>
          </div>
        </template>
      </el-collapse-item>
      <el-collapse-item
        v-if="
          detail &&
          detail.warningProblemAssign &&
          parseInt(detail.warningProblemAssign.status) == 1
        "
        title="问题处置"
        name="6"
      >
        <!-- 处置新增 -->
        <template
          v-if="
            detail.warningProblemAssignSolve == null ||
            detail.warningProblemAssignSolve.status == 0
          "
        >
          <!-- 纪委部门 -->
          <template>
            <DCPunish
              v-if="detail.type == 1"
              :detail="detail"
              @refresh="initData"
            ></DCPunish>
          </template>
          <!-- 行业主管部门 -->
          <template v-if="detail.type == 2">
            <el-form
              :model="punishForm"
              ref="punishForm"
              :rules="punishRules"
              label-width="150px"
              :inline="false"
            >
              <el-form-item label="处置结果" prop="solve_result">
                <el-input
                  type="textarea"
                  v-model="punishForm.solve_result"
                  :autosize="{
                    minRows: 3,
                    maxRows: 6,
                  }"
                ></el-input>
              </el-form-item>
              <el-form-item label="处置结果附件" prop="">
                <CommonUpload
                  tableName="question-transfer-punish"
                  useType="punish"
                ></CommonUpload>
              </el-form-item>
              <el-form-item label="处置时间" prop="solve_date">
                <el-date-picker
                  v-model="punishForm.solve_date"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item label="行政处罚内容" prop="punish_content">
                <el-input
                  type="textarea"
                  v-model="punishForm.punish_content"
                  :autosize="{
                    minRows: 3,
                    maxRows: 6,
                  }"
                ></el-input>
              </el-form-item>
              <el-form-item label="行政处罚内容附件" prop="">
                <CommonUpload
                  tableName="question-transfer-punish"
                  useType="punishXZ"
                ></CommonUpload>
              </el-form-item>
              <el-form-item label="行政处罚时间" prop="punish_date">
                <el-date-picker
                  v-model="punishForm.punish_date"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item label="承办人" prop="undertake_user_name">
                <el-input v-model="punishForm.undertake_user_name"></el-input>
              </el-form-item>
              <el-form-item label="承办单位" prop="">
                <el-input v-model="user.dept_name" disabled></el-input>
              </el-form-item>
              <el-form-item label="">
                <el-button type="primary" @click="savePunish">提交</el-button>
              </el-form-item>
            </el-form>
          </template>
        </template>
        <!-- 处置详情 -->
        <template
          v-if="
            detail.warningProblemAssignSolve &&
            detail.warningProblemAssignSolve.status == 1
          "
        >
          <!-- 纪委 -->
          <template v-if="detail.type == 1">
            <div class="desc">
              <label>处置时间：</label>
              <span>
                {{ detail.warningProblemAssignSolve.solve_date }}
              </span>
            </div>
            <div class="desc">
              <label>处置单位：</label>
              <span>
                {{ detail.warningProblemAssignSolve.solve_dept_name }}
              </span>
            </div>
            <div class="desc">
              <label>承办人：</label>
              <span>
                {{ detail.warningProblemAssignSolve.undertake__user_name }}
              </span>
            </div>
            <div class="desc">
              <label>是否属实：</label>
              <span>
                {{ detail.warningProblemAssignSolve.true_type }}
              </span>
            </div>
            <div class="desc">
              <label>是否转问题线索：</label>
              <span>
                {{
                  detail.warningProblemAssignSolve.problem_clues == 0
                    ? "否"
                    : "是"
                }}
              </span>
            </div>
            <div class="desc">
              <label>处置结果：</label>
              <span>
                {{ detail.warningProblemAssignSolve.solve_result }}
              </span>
            </div>
            <div class="desc">
              <label>处置结果附件：</label>
              <CommonUpload
                tableName="question-transfer-punish"
                :useType="'czjg'"
                :pid="detail.warningProblemAssignSolve.id"
                :showUploadBtn="false"
                :disabled="true"
              ></CommonUpload>
            </div>
            <div class="desc">
              <label>四种形态处理结果：</label>
              <el-table
                :data="detail.warningProblemAssignSolve.fourFormsList"
                border
                stripe
              >
                <el-table-column
                  label="姓名"
                  prop="user_name"
                  width="100"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  label="工作单位"
                  prop="dept_name"
                  min-width="150"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  label="职务"
                  prop="duty_level"
                  min-width="150"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  label="岗位"
                  prop="post"
                  min-width="150"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  label="组织措施"
                  prop="solve_mode"
                  min-width="150"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  label="党纪处分"
                  prop="party_punish"
                  min-width="150"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  label="政务处分"
                  prop="gov_punish"
                  min-width="150"
                  align="center"
                >
                </el-table-column>
              </el-table>
            </div>
            <div class="desc">
              <label>建章立制：</label>
              <span>
                {{ detail.warningProblemAssignSolve.create_system }}
              </span>
            </div>
            <div class="desc">
              <label>建章立制附件：</label>
              <CommonUpload
                tableName="question-transfer-punish"
                :useType="'jzlz'"
                :pid="detail.warningProblemAssignSolve.id"
                :showUploadBtn="false"
                :disabled="true"
              ></CommonUpload>
            </div>
            <div class="desc">
              <label>挽回经济损失：</label>
              <span>
                {{ detail.warningProblemAssignSolve.save_money }} 万元
              </span>
            </div>
          </template>
          <!-- 行业主管部门 -->
          <template v-if="detail.type == 2">
            <div class="desc">
              <label>处置结果：</label>
              <span>
                {{ detail.warningProblemAssignSolve.solve_result }}
              </span>
            </div>
            <div class="desc">
              <label>附件：</label>
              <CommonUpload
                tableName="question-transfer-punish"
                useType="punish"
                :pid="detail.warningTransfer.id"
                :showUploadBtn="false"
                :disabled="true"
              >
              </CommonUpload>
            </div>
            <div class="desc">
              <label>处置时间：</label>
              <span>
                {{ detail.warningProblemAssignSolve.solve_date }}
              </span>
            </div>
            <div class="desc">
              <label>行政处罚内容：</label>
              <span>
                {{ detail.warningProblemAssignSolve.punish_content }}
              </span>
            </div>
            <div class="desc">
              <label>附件：</label>
              <CommonUpload
                tableName="question-transfer-punish"
                useType="punishXZ"
                :pid="detail.warningTransfer.id"
                :showUploadBtn="false"
                :disabled="true"
              ></CommonUpload>
            </div>
            <div class="desc">
              <label>行政处罚时间：</label>
              <span>
                {{ detail.warningProblemAssignSolve.punish_date }}
              </span>
            </div>
            <div class="desc">
              <label>承办人：</label>
              <span>
                {{ detail.warningProblemAssignSolve.status_text }}
              </span>
            </div>
            <div class="desc">
              <label>承办单位：</label>
              <span>
                {{ detail.warningProblemAssignSolve.undertake_dept_name }}
              </span>
            </div>
          </template>
        </template>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import {
  getTransferDetail,
  postTransferAccept,
  postTransferAssign,
  postTransferFeedback,
  postTransferPunish,
} from "@/api/QuestionTransfer/Index";
import CommonUpload from "@/components/Common/CommonUpload.vue";
import OperateCommon from "@/components/Common/OperateCommon.vue";
import LinkTo from "@/mixins/LinkTo";
import { required } from "@/utils/eValidate";
import { getCurrentDate, getCurrentDateTime } from "@/utils/date";
import DeptCascader from "@/components/Common/DeptCascader.vue";
import { getDeptTree } from "@/api/System/Department";
import uploadMixin from "@/components/GenerateForm/uploadMixin";
import DCPunish from "./DCPunish.vue";
export default {
  name: "ProblemDetail",
  mixins: [LinkTo, uploadMixin],
  components: { CommonUpload, OperateCommon, DeptCascader, DCPunish },
  data() {
    return {
      id: 0,
      pageType: 0,
      activeNames: ["2", "3"],
      detail: null,
      user: null,
      acceptForm: {
        receive_opinion: "", // 接收意见
        // receive_time: "", // 接收时间
      },
      acceptRules: {
        receive_opinion: [required],
      },
      dept: [],
      assignForm: {
        assign_date: getCurrentDate(), // 交办日期
        assign_dept_id: "", // 交办单位 ID
        assign_dept_name: "", // 名称
        problem_desc: "", // 问题描述
        undertake_dept_id: "", // 承办单位 ID
        undertake_dept_name: "", // 承办单位 名称
        assign_opinion: "", // 交办意见
      },
      assignRules: {
        assign_dept_id: [required],
        problem_desc: [required],
        undertake_dept_id: [required],
        assign_opinion: [required],
      },
      feedbackForm: {
        feedback: "",
      },
      feedbackRules: {
        feedback: [required],
      },
      punishForm: {
        solve_result: "", // 处置结果
        solve_date: "", // 	处置时间
        punish_content: "", // 	行政处罚内容
        punish_date: "", // 行政处罚时间
        undertake_user_name: "", // 承办人 手输
        undertake_dept_name: "", // 承办单位 当前
      },
      punishRules: {
        solve_result: [required],
        solve_date: [required],
        punish_content: [required],
        punish_date: [required],
        undertake_user_name: [required],
      },
    };
  },
  methods: {
    initDept() {
      getDeptTree().then((res) => {
        if (res.code == 0) {
          this.dept = res.data;
        }
      });
    },
    initData() {
      getTransferDetail({
        id: this.id,
      }).then((res) => {
        if (res.code == 0) {
          this.detail = res.data;
        }
      });
    },
    goBack() {
      switch (parseInt(this.pageType)) {
        case 0:
          this.linkTo(`/problemTransfer/assign`);
          break;
        case 1:
          this.linkTo(`/problemTransfer/solving`);
          break;
      }
    },
    acceptProblem() {
      this.$refs.acceptForm.validate((valid) => {
        if (valid) {
          this.acceptForm.receive_time = getCurrentDateTime();
          this.acceptForm.id = this.detail.warningTransfer.id;
          postTransferAccept(this.acceptForm).then((res) => {
            if (res.code == 0) {
              this.$message.success("接收成功");
              this.initData();
            }
          });
        }
      });
    },
    feedbackProblem(status) {
      this.$refs.feedbackForm.validate((valid) => {
        if (valid) {
          this.feedbackForm.transfer_id = this.detail.warningTransfer.id;
          this.feedbackForm.id = this.detail.warningProblemAssign.id;
          this.feedbackForm.status = status;
          this.feedbackForm.status_text = status == 1 ? "已反馈" : "已退回";
          this.feedbackForm.feedback_date = getCurrentDateTime();
          postTransferFeedback(this.feedbackForm).then((res) => {
            if (res.code == 0) {
              this.$message.success("问题交办反馈成功");
              this.initData();
            }
          });
        }
      });
    },
    assignProblem() {
      this.$refs.assignForm.validate((valid) => {
        if (valid) {
          this.assignForm.transfer_id = this.detail.warningTransfer.id;
          postTransferAssign(this.assignForm).then((res) => {
            if (res.code == 0) {
              this.$message.success("交办成功");
              this.initData();
              this.checkFile(res.data);
            }
          });
        }
      });
    },
    savePunish() {
      this.$refs.punishForm.validate((valid) => {
        if (valid) {
          this.punishForm.warning_assign_id =
            this.detail.warningProblemAssign.id;
          postTransferPunish(this.punishForm).then((res) => {
            if (res.code == 0) {
              this.$message.success("提交成功");
              this.initData();
              this.checkFile(res.data);
            }
          });
        }
      });
    },
    changeAssignDept(val) {
      this.assignForm.assign_dept_id = val.value;
      this.assignForm.assign_dept_name = val.label;
    },
    changeDept(val) {
      this.assignForm.undertake_dept_id = val.value;
      this.assignForm.undertake_dept_name = val.label;
    },
  },
  created() {
    this.id = this.$route.params.id;
    this.pageType = this.$route.params.type;
    this.user = JSON.parse(localStorage.getItem("user"));

    this.assignForm.assign_dept_id = JSON.parse(
      localStorage.getItem("user")
    ).dept_id;

    this.assignForm.assign_dept_name = JSON.parse(
      localStorage.getItem("user")
    ).dept_name;

    this.initDept();
    this.initData();
  },
};
</script>

<style lang="scss" scoped>
</style>